package daily.kou2022_0123;

import java.util.Stack;
//155. 最小栈
public class MinStack {
    //s1是实际上储存元素的栈
    private Stack<Integer>s1=new Stack<>();
    //s2是存储最小值的栈
    private Stack<Integer> s2 = new Stack<>();
    //无参构造
    public MinStack() {

    }

    public void push(int val) {
        s1.push(val);
        if (s2.isEmpty()){
            s2.push(val);

        }else {
            s2.push(Math.min(s2.peek(),val));
        }

    }

    public void pop() {
        s1.pop();
        s2.pop();

    }

    public int top() {
        return s1.peek();

    }

    public int getMin() {
        return s2.peek();

    }



}
